﻿package mortal.game.scene3D.display3d.text3d.dynamicText3d
{
    import baseEngine.core.*;
    import flash.text.*;
    import flash.utils.*;
    import mortal.game.scene3D.*;

    public class WidthType extends Object
    {
        private var heightMap:Dictionary;
        private var curText3dBig:Text3DBigImg;
        private var listArr:Array;
        private var _width:int = 0;
        private var _scene:GameScene3D;

        public function WidthType(param1:int)
        {
            this.heightMap = new Dictionary(false);
            this.listArr = new Array();
            this._width = param1;
            return;
        }// end function

        public function init(param1:GameScene3D) : void
        {
            var _loc_2:Text3DBigImg = null;
            this._scene = param1;
            for each (_loc_2 in this.listArr)
            {
                
                _loc_2.init(this._scene);
            }
            return;
        }// end function

        public function reinit(param1:GameScene3D) : void
        {
            var _loc_2:Text3DBigImg = null;
            for each (_loc_2 in this.listArr)
            {
                
                _loc_2.reinit(this._scene);
            }
            return;
        }// end function

        public function checkAndDispose() : Boolean
        {
            var _loc_3:Text3DBigImg = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_7:int = 0;
            var _loc_1:* = getTimer();
            var _loc_2:* = new Array();
            for each (_loc_3 in this.listArr)
            {
                
                if (_loc_3.canDispose(_loc_1))
                {
                    _loc_2.push(_loc_3);
                }
            }
            _loc_4 = _loc_2.length;
            _loc_5 = 0;
            while (_loc_5 < _loc_4)
            {
                
                _loc_3 = _loc_2[_loc_5];
                _loc_3.disposeAll(this.heightMap);
                _loc_7 = this.listArr.indexOf(_loc_3);
                this.listArr.splice(_loc_7, 1);
                _loc_5++;
            }
            var _loc_6:* = _loc_2.indexOf(this.curText3dBig);
            if (_loc_6 != -1)
            {
                this.curText3dBig = this.listArr.length == 0 ? (null) : (this.listArr[(this.listArr.length - 1)]);
            }
            return _loc_4 > 0;
        }// end function

        public function checkAndUpload(param1:GameScene3D) : Boolean
        {
            var _loc_4:Text3DBigImg = null;
            var _loc_2:* = this.listArr.length;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2)
            {
                
                _loc_4 = this.listArr[_loc_3];
                if (_loc_4.needUpload)
                {
                    _loc_4.uploadTexture(param1);
                    return true;
                }
                _loc_3++;
            }
            return false;
        }// end function

        private function getPosInfo(param1:TextField) : Text3DInfo
        {
            var _loc_2:* = param1.htmlText;
            var _loc_3:* = this.heightMap[_loc_2];
            if (!_loc_3)
            {
                if (!this.curText3dBig || this.curText3dBig.isFull(param1.height))
                {
                    this.curText3dBig = new Text3DBigImg(this._width);
                    if (this._scene)
                    {
                        this.curText3dBig.init(this._scene);
                    }
                    this.listArr.push(this.curText3dBig);
                }
                var _loc_4:* = this.curText3dBig.createPos(param1, _loc_2);
                _loc_3 = this.curText3dBig.createPos(param1, _loc_2);
                this.heightMap[param1.htmlText] = _loc_4;
            }
            return _loc_3;
        }// end function

        public function createText3D(param1:TextField, param2:Boolean, param3:Pivot3D) : Text3D
        {
            var _loc_4:* = this.getPosInfo(param1);
            var _loc_5:* = _loc_4.targetBigImg.createText3D(param1, _loc_4, param2, param3);
            _loc_5.show();
            return _loc_5;
        }// end function

        public function updateText3D(param1:Text3D, param2:TextField, param3:Pivot3D) : void
        {
            var _loc_4:* = this.getPosInfo(param2);
            var _loc_5:* = param1.isHide;
            var _loc_6:* = _loc_4.targetBigImg.createText3D(param2, _loc_4, param1.needMoving, param3, param1);
            if (_loc_5)
            {
                _loc_6.hide();
            }
            else
            {
                _loc_6.show();
            }
            return;
        }// end function

    }
}
